home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 266_01 / imaglib.c < prev    next >
C/C++ Source or Header  |  1990-04-30  |  2KB  |  117 lines

  1. /*            In-memory image managing library        FILE: IMAGLIB.C
  2.                  for pixel printer devices
  3.                  Robert L. (Bob) Patton, Jr.
  4.                    1713 Parkcrest Terrace
  5.                     Arlington, TX 76012
  6.                        27 April 1990
  7. */
  8. #include "PLOX.H"
  9. #include "lptr.h"
  10.  
  11. #define VSIZE      (YMAX+7)/8
  12. static char Image[XMAX+1][VSIZE];
  13.  
  14. void Dot (X,Y)
  15. /*   ===      Turns on the pixel at X,Y  */
  16. int X,Y;
  17. {
  18.   int V;
  19.   if (InBounds(X,Y)) {
  20.     V = YMAX/8 - Y/8;
  21.     Image[X][V] = Image[X][V] | Bit(Y%8);
  22.   }
  23. }
  24.  
  25. /*
  26.      This version of Draw is for Epson compatible printer devices
  27. */
  28. void Draw(Xmax,Ymax,Bold)
  29. /*   ====  Draws the memory image on the printer.  */
  30. int  Xmax,Ymax,Bold;
  31. #define GRAPHICS  8
  32. #define NORMAL   12
  33. #define CR       13
  34. {
  35.   unsigned I,J;
  36.   Ymax=(Ymax+7)/8;
  37.   LP_LineSpace(GRAPHICS);
  38.   LP_CrLf(1);
  39.   if (Xmax<=0 || Xmax>XMAX) Xmax=XMAX;
  40.   for (J=((Ymax<=0)?0:VSIZE-Ymax); J<VSIZE; J++)
  41.   {
  42.     LP_GraphMode(Xmax+1);
  43.     for (I=0; I<=Xmax; I++)
  44.       LP_Send(Image [I][J]);
  45.     if (Bold) {
  46.       LP_Send(CR);
  47.       LP_GraphMode(Xmax+1);
  48.       for (I=0; I<=Xmax; I++)
  49.         LP_Send(Image[I][J]);
  50.     }
  51.     LP_CrLf(1);
  52.   }
  53.   LP_LineSpace(NORMAL);
  54.   LP_Reset();
  55.   LP_CrLf(1);
  56. }
  57.  
  58. void Line (X1,Y1,X2,Y2)
  59. /*   ====               Draws a straight line */
  60. int  X1,Y1,X2,Y2;
  61. {
  62.   int Dx, Dy, D1x, D1y, D2x, D2y, M, N, S, K;
  63.  
  64.   Dx = X2 - X1;
  65.   Dy = Y2 - Y1;
  66.   D1x = Sign(Dx);
  67.   D1y = Sign(Dy);
  68.   D2x = D1x;
  69.   D2y = 0;
  70.   M = abs(Dx);
  71.   N = abs(Dy);
  72.   if (M <= N) {
  73.     D2x = 0;
  74.     D2y = D1y;
  75.     M = abs(Dy);
  76.     N = abs(Dx);
  77.   }
  78.   S = M/2;
  79.   for (K=0; K<=M; K++)
  80.   {
  81.     if (Dotter())  Dot (X1,Y1);
  82.     S += N;
  83.     if (S >= M) {
  84.       S -= M;
  85.       X1 += D1x;
  86.       Y1 += D1y;
  87.     }
  88.     else {
  89.       X1 += D2x;
  90.       Y1 += D2y;
  91.     }
  92.   }
  93. }
  94.  
  95. void NewImage()
  96. /*   ========   Clears the plot image (to binary zeros) */
  97. {
  98. unsigned K,Kmax;
  99. char    *Image_Ptr;
  100.   Image_Ptr=&Image[0];
  101.   Kmax=(XMAX+1)*(VSIZE);
  102.   for (K=0; K<Kmax; K++,Image_Ptr++)
  103.     *Image_Ptr = 0;
  104. }
  105.  
  106. void NoDot (X,Y)
  107. /*   =====      Turns off the pixel at X,Y  */
  108. int X,Y;
  109. {
  110.   int V;
  111.   if (InBounds(X,Y)) {
  112.     V = YMAX/8 - Y/8;
  113.     Image[X][V] = Image[X][V] & (~Bit(Y%8));
  114.   }
  115. }
  116.  
  117.